package com.webproject.service.impl.sysManager;

import com.webproject.core.Page;
import com.webproject.dao.sysManager.RoleManagerDao;
import com.webproject.dao.sysManager.UserManagerDao;
import com.webproject.entity.sysManager.Role;
import com.webproject.entity.sysManager.RoleMenuRelation;
import com.webproject.entity.sysManager.UserRoleRelation;
import com.webproject.service.sysManager.RoleManagerService;

public class RoleManagerServiceImpl implements RoleManagerService {

	private RoleManagerDao roleManagerDao;
	private UserManagerDao userManagerDao;
	public void setUserManagerDao(UserManagerDao userManagerDao) {
		this.userManagerDao = userManagerDao;
	}

	public RoleManagerDao getRoleManagerDao() {
		return roleManagerDao;
	}

	public void setRoleManagerDao(RoleManagerDao roleManagerDao) {
		this.roleManagerDao = roleManagerDao;
	}

	@Override
	public void queryRoles(Page page) {
		// TODO Auto-generated method stub
		page.setRows(roleManagerDao.queryRoles(page));
		page.setRecords(roleManagerDao.queryRolesCount(page));
	}

	@Override
	public void saveRole(Role role) {
		// TODO Auto-generated method stub
		roleManagerDao.saveRole(role);
	}

	@Override
	public void editRole(Role role) {
		// TODO Auto-generated method stub
		roleManagerDao.updateRole(role);
	}

	@Override
	public void delRole(Role role) {
		// TODO Auto-generated method stub
		//删除用户对应的角色
		UserRoleRelation userRoleRelation=new UserRoleRelation();
		userRoleRelation.setRoleId(role.getId());
		userManagerDao.delUserRoleRelation(userRoleRelation);
		//删除角色对应功能
		RoleMenuRelation relation=new RoleMenuRelation();
		relation.setRoleId(role.getId());
		roleManagerDao.delRoleMenuRelation(relation);
		//删除角色
		roleManagerDao.delRole(role);
	}

	@Override
	public void saveRoleMenuRelation(RoleMenuRelation relation) {
		// TODO Auto-generated method stub
		roleManagerDao.saveRoleMenuRelation(relation);
	}

	@Override
	public void delRoleMenuRelation(RoleMenuRelation relation) {
		// TODO Auto-generated method stub
		roleManagerDao.delRoleMenuRelation(relation);
	}

}
